package com.zlx.sharelive.activity;

import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import com.zlx.module_base.base_ac.BaseAc;
import com.zlx.module_base.base_util.StringUt;
import com.zlx.sharelive.R;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.BindView;
import butterknife.OnClick;

public class WebViewActivity extends BaseAc {

    @BindView(R.id.wv_view)
    WebView wv_view;
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_title1)
    TextView tv_title1;

    private String title;
    private String content;
    private String type = "";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_webview;
    }

    @Override
    public void initViews() {
        super.initViews();

        title = getIntent().getStringExtra("title");
        content = getIntent().getStringExtra("content");
        type = getIntent().getStringExtra("type");
        switch (type) {
            case "3":
                tv_title.setText("用户协议");
                break;
            case "4":
                tv_title.setText("隐私协议");
                break;
            case "2":
                tv_title.setText("平台协议");
                break;
            case "5":
                tv_title.setText("会员服务协议");
                break;
            case "6":
                tv_title.setText("充值帮助");
                break;
        }

        tv_title1.setText(title);

        String html = content;
        if (StringUt.isEmpty(html)) {
            html = "";
        } else {
            html = replaceImgStyle(html);
        }
        wv_view.loadDataWithBaseURL(null, html, "text/html",
                "UTF-8", null);
    }

    @OnClick(R.id.iv_back)
    public void setOnClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    private String replaceImgStyle(String html) {
        String reg = "style=\"([^\"]+)\"";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(html);
        return matcher.replaceAll("");
    }
}
